package CourseSelectionSystem;

import java.util.ArrayList;
import java.util.List;

public class Teacher extends Person {
    private List<Course> teachingCourses;  // 改为列表，支持多个课程

    public Teacher(String id, String name, String gender) {
        super(id, name, gender);
        this.teachingCourses = new ArrayList<>();
    }

    public void assignCourse(Course course) {
        this.teachingCourses.add(course);
        course.setTeacher(this);
    }

    public List<Course> getTeachingCourses() {
        return teachingCourses;
    }

    // 添加打印教师课程表方法
    public void printTeachingSchedule() {
        System.out.println("\n👨‍🏫 " + getName() + " 的授课课表");
        System.out.println("基本信息: " + getBasicInfo());
        System.out.println("=" + "=".repeat(100));

        if (teachingCourses.isEmpty()) {
            System.out.println("   暂无授课课程");
        } else {
            System.out.printf("%-12s %-15s %-10s %-15s %-20s %-8s%n",
                    "课程编号", "课程名称", "上课地点", "上课时间", "选课人数", "学分");
            System.out.println("-".repeat(100));

            for (Course course : teachingCourses) {
                System.out.printf("%-12s %-15s %-10s %-15s %-20s %-8d%n",
                        course.getCourseId(),
                        course.getCourseName(),
                        course.getLocation(),
                        course.getTime(),
                        course.getEnrolledCount() + "/" + course.getCapacity(),
                        course.getCredits());
            }

            // 显示统计信息
            System.out.println("-".repeat(100));
            int totalStudents = teachingCourses.stream().mapToInt(Course::getEnrolledCount).sum();
            int totalCapacity = teachingCourses.stream().mapToInt(Course::getCapacity).sum();
            System.out.printf("%-72s %-8s%n", "总授课课程数:", teachingCourses.size() + "门");
            System.out.printf("%-72s %-8s%n", "总选课学生数:", totalStudents + "/" + totalCapacity + "人");
        }
        System.out.println("=" + "=".repeat(100));
    }

    // 原有的单个课程方法保持不变（为了兼容性）
    public Course getTeachingCourse() {
        return teachingCourses.isEmpty() ? null : teachingCourses.get(0);
    }

    // 原有的打印授课信息方法
    public void printTeachingCourse() {
        System.out.println("\n👨‍🏫 " + getName() + " 的授课信息");
        System.out.println("基本信息: " + getBasicInfo());
        System.out.println("=".repeat(60));

        if (!teachingCourses.isEmpty()) {
            System.out.println("授课课程数: " + teachingCourses.size() + "门");
            for (Course course : teachingCourses) {
                System.out.println("课程名称: " + course.getCourseName());
                System.out.println("课程编号: " + course.getCourseId());
                System.out.println("上课时间: " + course.getTime());
                System.out.println("上课地点: " + course.getLocation());
                System.out.println("选课人数: " + course.getEnrolledCount() + "/" + course.getCapacity());
                System.out.println("课程学分: " + course.getCredits());
                System.out.println("-".repeat(40));
            }
        } else {
            System.out.println("暂无授课课程");
        }
        System.out.println("=".repeat(60));
    }
}